﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.QLMS.Entity;
using ZDSoft.QLMS.Entity.SystemSetting;
using ZDSoft.QLMS.Component.SystemSettingComponent;

namespace ZDSoft.QLMS.Component
{
    public class UserCourseComponent : ComponentBase<UserCourse>
    {
        OrganizationComponent OrganizationComponent = new OrganizationComponent();
        UserComponent UserComponent = new UserComponent();
        public IList<UserCourse> GetallUserCourse(int id)
        {
            Organization entity = OrganizationComponent.FindByID(id);
            IList<Course> modle = new CourseComponent().FindAll();
            IList<UserCourse> UserCourslist = new List<UserCourse>();
            foreach (Course entityone in modle)
            {
                if (entityone.Organization != null && entityone.Organization.ID == id)
                {
                    foreach (UserCourse UserCourseentity in entityone.UserCourses)
                    {
                        UserCourslist.Add(UserCourseentity);
                    }
                }
            }
            return UserCourslist;
        }
        public void command(string selectedUserId)
        {
            IList<string> UserIdlist = selectedUserId.Split(',');
            foreach (string UserId in UserIdlist)
           {
               if (UserId!="")
                {
                    User entity = UserComponent.FindByID(int.Parse(UserId));
                    entity.IsReset = true;
                    entity.Update();
                }
           }
        }
    }
}